<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
    <div class="box">
      <div class="heading">
        <h1><img src="view/image/report.png" alt="" /> <?php echo $heading_title; ?></h1>
        <div class="buttons">
                  <a onclick="filter();" class="button">Fillter</a>
                  
                  <a align="center" onclick="window.open('<?php echo $export_excel; ?>', '_blank')" class="button"><?php echo $button_export_excel; ?></a>                
        </div>
      </div>        
      <div class="content">
           
       <form action="" method="post" enctype="multipart/form-data" id="form">
        <table class="list">
         <thead>
          <tr>             
              <td class="left" style="width: 220px"><?php if ($sort == 'last_name') { ?>
                <a href="<?php echo $sort_lastname; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_lastname; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_lastname; ?>"><?php echo $column_lastname; ?></a>
                <?php } ?></td>  
              <td class="left" style="width: 220px"><?php if ($sort == 'first_name') { ?>
                <a href="<?php echo $sort_firstname; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_firstname; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_firstname; ?>"><?php echo $column_firstname; ?></a>
                <?php } ?></td>  
                 <td class="left" style="width: 200px"><?php if ($sort == 'phone_mobile') { ?>
                <a href="<?php echo $sort_phonemobile; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_phonemobile; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_phonemobile; ?>"><?php echo $column_phonemobile; ?></a>
                <?php } ?></td>  
                  <td class="left" style="width: 200px"><?php if ($sort == 'birthday') { ?>
                <a href="<?php echo $sort_birthday; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_birthday; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_birthday; ?>"><?php echo $column_birthday; ?></a>
                <?php } ?></td> 
                  <td class="left" style="width: 100px"><?php if ($sort == 'points') { ?>
                <a href="<?php echo $sort_point; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_point; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_point; ?>"><?php echo $column_point; ?></a>
                <?php } ?></td> 
                  <td class="center" style="width: 200px"><?php echo $column_district?></td>
                  <td class="center" style="width: 200px"><?php echo $column_city?></td>
                  <td class="center" style="width: 200px"><?php echo $column_email?></td>
                  <td class="center" style="width: 200px"><?php echo $column_bills?></td>
                  <td class="center" style="width: 200px"><?php echo $column_customer?></td>                 
          </tr>
        </thead>
        <tbody> 
            <tr class="filter">
              <td><input type="text" name="last_name" value="<?php echo $last_name; ?>" style="width: 120px" /></td>
              <td><input type="text" name="first_name" value="<?php echo $first_name; ?>" style="width: 120px" /></td>
              <td align="left" style="width: 100px"><input type="text" name="phonemobile" value="<?php echo $phonemobile; ?>" size="8" style="width: 120px" /></td>              
             <td align="left" >
               <!--   <input type="text" name="birthday" value="<?php echo $birthday; ?>" size="8" id="birthday" style="width: 120px" /> -->           
             <table >
              <tr>
                <td>Ngày</td>
                <td>Tháng</td>
                 <td>Năm</td>
              </tr>
              <tr>
                  <td><input type="text" name="day"  value="<?php echo $day; ?>" style="width: 30px"  /></td>
                  <td><input type="text" name="month" value="<?php echo $month; ?>"  style="width: 30px" /></td>
                  <td><input type="text" name="year" value="<?php echo $year; ?>" style="width: 50px" /></td>
              </tr>
                </table>
              </td>
              <td><input type="text" name="point" value="<?php echo $point; ?>" style="width: 120px" /></td>
              <td><input type="text" name="district" value="<?php echo $district; ?>" style="width: 100px" /></td>
              <td><input type="text" name="city" value="<?php echo $city; ?>" style="width: 100px"/></td>
                <td><input type="text" name="email" value="<?php echo $email; ?>" style="width: fit-content"/></td>
              <td style="width: 120px;"></td>            
              <td style="width: 120px;"></td>
            </tr>
            <?php if($customers!=null) { ?>
            <?php foreach ($customers as $customer) { ?>
             <tr>
            <td><?php echo $customer['last_name']?></td>
            <td><?php echo $customer['first_name']?></td>
            <td><?php echo $customer['phone_mobile']?></td>
            <td><?php echo $customer['birthday']?></td>
            <td><?php echo $customer['points']?></td>  
            <td><?php echo $customer['district']?></td>   
            <td><?php echo $customer['city']?></td>   
            <td><?php echo $customer['email']?></td>   
            <td class="center"><?php foreach ($customer['bills'] as $bill) { ?>
                 <a href="<?php echo $bill['href']; ?>">Chi tiết</a> 
                <?php } ?></td> 
            <td class="center"> <a href="<?php echo $customer['href1']; ?>">Chi Tiết</a></td>
            <?php } ?>
            <?php } ?>       
             </tr>  
        </tbody>
        </table>
           </form>
             <div class="pagination"><?php echo $pagination; ?></div>
        </div>      
    </div>   
</div>
<script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=Mart_Crm/Crm_customer&token=<?php echo $token; ?>';
	
	var last_name = $('input[name=\'last_name\']').attr('value');
	
	if (last_name) {
		url += '&last_name=' + encodeURIComponent(last_name);
	}
	var first_name = $('input[name=\'first_name\']').attr('value');
	
	if (first_name) {
		url += '&first_name=' + encodeURIComponent(first_name);
	}
	var phonemobile = $('input[name=\'phonemobile\']').attr('value');
	
	if (phonemobile) {
		url += '&phonemobile=' + encodeURIComponent(phonemobile);
	}
	var district = $('input[name=\'district\']').attr('value');
	
	if (district) {
		url += '&district=' + encodeURIComponent(district);
	}
        var city = $('input[name=\'city\']').attr('value');
	
	if (city) {
		url += '&city=' + encodeURIComponent(city);
	}
	var point = $('input[name=\'point\']').attr('value');
	
	if (point) {
		url += '&point=' + encodeURIComponent(point);
	}
	
        var day = $('input[name=\'day\']').attr('value');
	
	if (day) {
		url += '&day=' + encodeURIComponent(day);
	}
         var month = $('input[name=\'month\']').attr('value');
	
	if (month) {
		url += '&month=' + encodeURIComponent(month);
	}
         var year = $('input[name=\'year\']').attr('value');
	
	if (year) {
		url += '&year=' + encodeURIComponent(year);
	}
         var email = $('input[name=\'email\']').attr('value');
	
	if (email) {
		url += '&email=' + encodeURIComponent(email);
	}
	location = url;
}
//--></script> 
<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});
//--></script> 
<script type="text/javascript"><!--
$('input[name=\'last_name\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=Mart_Crm/Crm_customer/autocomplete&token=<?php echo $token; ?>&last_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.last_name
						//value: item.last_name
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'last_name\']').val(ui.item.label);
						
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});
$('input[name=\'phonemobile\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=Mart_Crm/Crm_customer/autocomplete&token=<?php echo $token; ?>&phonemobile=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.phonemobile
						//value: item.last_name
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'phonemobile\']').val(ui.item.label);
						
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});
$('input[name=\'first_name\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=Mart_Crm/Crm_customer/autocomplete&token=<?php echo $token; ?>&first_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.first_name
						//value: item.first_name
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'first_name\']').val(ui.item.label);
						
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});

$('input[name=\'email\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=Mart_Crm/Crm_customer/autocomplete&token=<?php echo $token; ?>&email=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.email
						//value: item.first_name
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'email\']').val(ui.item.label);
						
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});


$('input[name=\'district\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=Mart_Crm/Crm_customer/autocomplete&token=<?php echo $token; ?>&district=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.district
						//value: item.last_name
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'district\']').val(ui.item.label);
						
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});
$('input[name=\'city\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=Mart_Crm/Crm_customer/autocomplete&token=<?php echo $token; ?>&city=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.city
						//value: item.last_name
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'city\']').val(ui.item.label);
						
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});
//--></script> 
<script type="text/javascript"><!--
$(document).ready(function() {
	$('#birthday').datepicker({dateFormat: 'dd-mm-yy'});
	
});
//--></script> 
<?php echo $footer; ?>
